<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>网站信息</title>
    <link rel="stylesheet" href="${ctxPath}/assets/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="${ctxPath}/assets/module/admin.css">
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>

<form id="addOrUpdateForm" lay-filter="addOrUpdateForm" class="layui-form model-form">

    <input name="id" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">站点域名</label>
        <div class="layui-input-block">
            <input name="domain" class="layui-input" placeholder="请输入站点域名" lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">网站logo</label>
        <div class="layui-input-block">
            <div class="layui-upload-drag" id="logoFile">
                <i class="layui-icon"></i>
                <p>点击上传，或将图片拖拽到此处</p>
                <div class="layui-hide" id="uploadView">
                    <hr>
                    <img src="" alt="上传成功后渲染" style="max-width: 150px">
                </div>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-inline" style="width: 320px;">
            <label class="layui-form-label layui-form-required">站点标题</label>
            <div class="layui-input-block">
                <input name="title" class="layui-input" placeholder="请输入站点标题" lay-verType="tips" lay-verify="required" required/>
            </div>
        </div>

        <div class="layui-input-inline" style="width: 320px;">
            <label class="layui-form-label layui-form-required">副标题</label>
            <div class="layui-input-block">
                <input name="subtitle" class="layui-input" placeholder="请输入站点副标题" lay-verType="tips" lay-verify="required" required/>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">关键词</label>
        <div class="layui-input-block">
            <input name="keywords" class="layui-input" placeholder="请输入网站关键词" lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">网站描述</label>
        <div class="layui-input-block">
            <textarea name="description" class="layui-textarea" placeholder="请输入网站描述" ></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">站点备案</label>
        <div class="layui-input-block">
            <input name="icp" class="layui-input" placeholder="请输入站点备案" lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">统计代码</label>
        <div class="layui-input-block">
            <textarea name="statistical" class="layui-textarea" placeholder="请输入统计代码" ></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">版权</label>
        <div class="layui-input-block">
            <input name="copyright" class="layui-input" placeholder="请输入版权" lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>

    <div class="layui-form-item text-right">
        <button class="layui-btn" lay-filter="formSubmitBtn" lay-submit>保存</button>
    </div>
</form>
<script src="${ctxPath}/assets/libs/layui/layui.js"></script>
<script src="${ctxPath}/assets/js/common.js"></script>
<script>
    layui.use(['layer', 'form', 'admin', 'xnUtil', 'xmSelect', 'laydate','upload'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var admin = layui.admin;
        var xnUtil = layui.xnUtil;
        var xmSelect = layui.xmSelect;
        var laydate = layui.laydate;
        var upload = layui.upload;

        var imageUrl;

        var editData = null;

        $(document). ready(function(){
            admin.req(getProjectUrl() + 'web/getInfo',null, function(res){
                editData = res.data;
                layui.$('#uploadView').removeClass('layui-hide').find('img').attr('src', getProjectUrl() + editData.logo);
                form.val('addOrUpdateForm', editData);
            }, 'get');
        });

        //拖拽上传
        upload.render({
            elem: '#logoFile'
            ,field: "file"
            ,url: getProjectUrl() + 'sysFileInfo/minio/upload'
            ,accept: 'images'
            ,done: function(res){
                layer.msg('上传成功');
                layui.$('#uploadView').removeClass('layui-hide').find('img').attr('src', getProjectUrl() + 'sysFileInfo/minio/preview?id=' + res.data);
                imageUrl = 'sysFileInfo/minio/preview?id=' + res.data;
                console.log(res)
            }
        });

        /**
         * 表单提交事件
         */
        form.on('submit(formSubmitBtn)', function (data) {
            layer.load(2);

            var url = editData ? getProjectUrl() + 'web/edit' : getProjectUrl() + 'web/add';
            data.field.logo = editData ? (imageUrl ? imageUrl : editData.logo):imageUrl;
            admin.req(url, JSON.stringify(data.field), function(res){
                layer.msg(res.message, {icon: 1, time: 1000}, function () {
                    admin.putLayerData('formOk', true, '#addOrUpdateForm');
                    //admin.closeDialog('#addOrUpdateForm');
                });
            }, 'post');
            return false;
        });
    });


</script>
</body>
</html>
